<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- Select2 -->
<link href="<%=basePath%>vendors/select2/dist/css/select2.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">

<style type="text/css">
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=mENaiMKmd5sLVYOekAd3z9vmjOtkUS7m"></script>
</head>
<%@ include file="loginCheck.jsp"%>
<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>
			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left">
							<h3>商圈信息</h3>
						</div>
					</div>
					<div class="clearfix"></div>
					<div class="row">
						<div class="col-md-12 col-sm-12 col-xs-12">
							<div class="x_panel">
								<div class="x_title">
									<h2>修改商圈店铺信息</h2>
									<div class="clearfix"></div>
								</div>
								<div class="x_content">
									<form name="myForm" class="form-horizontal form-label-left"
										novalidate method="post" enctype="multipart/form-data"
										id="myForm">
										<p>
											请谨慎修改相关信息，如有修改错误请及时
											<code>联系客服</code>
											以帮助您完成相关配置
										</p>
										<span class="section">基本信息</span>
										<div class="item form-group" style="display: none">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">id<span class="required"></span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="id" name="id"
													class="form-control col-md-7 col-xs-12" type="text"
													value="${sotre.id}">
											</div>
										</div>
										<c:if test="${adminUsergrade==0}">
											<div class="item form-group">
												<label class="control-label col-md-3 col-sm-3 col-xs-12"
													for="name">所属应用 </label><span class="required"></span>
												<div class="col-md-6 col-sm-6 col-xs-12">
													<select class="form-control" id="parentid" name="parentid">
														<c:forEach items="${users}" var="s">
															<option value="${s.id}" <c:if test="${sotre.parentid == s.id}">selected</c:if>>${s.username}</option>
														</c:forEach>
													</select>
												</div>
											</div>
										</c:if>
										<div id="shop" class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">所属商家 </label>
											<div class="col-md-6 col-sm-6 col-xs-12" >
												<input class="form-control col-md-7 col-xs-12"
													name="shopname" placeholder="谨慎操作：即时修改用户所属商家（输入#号键结束）" required="required"
													type="text" value="" id="shopname">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">店铺名称 </label><span class="required"></span>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													name="sotrename" placeholder="例如：肯德基" required="required"
													type="text" value="${sotre.sotrename}" id="sotrename">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">店铺头像 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" id="logoFile"
													name="logoFile" required="required" type="file"
													placeholder="选择上传图片" form="formUpload"> <input
													id="logo" name="logo"
													class="form-control col-md-7 col-xs-12"
													style="display: none" type="text" value="${sotre.logo}">
											</div>
										</div>
										<div class="form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12">店铺简介 
											<span class="required">*</span></label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<textarea name="synopsis" id="synopsis" class="form-control">${sotre.synopsis}</textarea>
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">店铺地址</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													name="address" placeholder="为了确保定位准确，请输入详细的地址信息，例如：杭州市新塘路杭州新传媒产业大厦"
													required="required" type="text" value="${sotre.address}"
													id="address">
											</div>
											<input id="latitude" name="latitude" type="hidden"
												value="${sotre.latitude}" /> <input id="longitude"
												name="longitude" type="hidden" value="${sotre.longitude}" />
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">详细信息</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<div id="container" style="height: 249px; "></div>
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">背景图片 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" id="picFile"
													name="picFile" required="required" type="file"
													placeholder="选择上传图片" form="formUpload"> <input
													id="pic" name="pic" class="form-control col-md-7 col-xs-12"
													style="display: none" type="text" value="${sotre.pic}">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">营业时间 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													name="busintime" placeholder="例如：早上9:00-晚上9:00"
													required="required" type="text" value="${sotre.busintime}"
													id="busintime">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">联系电话 <span class="required">*</span></label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12" name="mobile"
													placeholder="例如：136952145365" required="required"
													type="text" value="${sotre.mobile}" id="mobile">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">折扣信息 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input class="form-control col-md-7 col-xs-12"
													name="discount" placeholder="例如：今日全店9折起..."
													required="required" type="text" value="${sotre.discount}"
													id="discount">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">优先级</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="grade" name="grade">
														<option value="1" <c:if test="${sotre.grade == 1}"> selected </c:if>>普通</option>
														<option value="2" <c:if test="${sotre.grade == 2}"> selected </c:if>>精选</option>
														<option value="3" <c:if test="${sotre.grade == 3}"> selected </c:if>>高级会员</option>
												</select>
											</div>
										</div>
										<div class="ln_solid"></div>
										<div class="form-group">
											<div class="col-md-6 col-md-offset-3">
												<a type="submit" class="btn btn-primary"
													href="javascript:void(0)"
													onclick="history.back(-1);">取消</a> <input
													type="button" id="revise" class="btn btn-success" value="修改" />
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- /page content -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<script type="text/javascript">
		// 修改用户所属商家
		$("#shopname").blur(function(event){
			var shopname = $(this).val();
			var partten = /^.{1,}#$/;
            if (!partten.test(shopname)) {
                return false;
            }
			$.ajax({
				type : 'POST',
				url : 'beanSnameAndUpsub',
				data : {
					shopname : shopname,
					subid : '${sotre.userid}'
				},
				success : function(date) {
					if (date == -1){
						alert("系统异常，请重新操作");
						top.location.href = "login/${titleId}";
					} else if (date == -2) {
						alert("该用户代理商下不存在此商家，请检查输入的商家名称是否正确");
					} else if (date > 0) {
						alert("所属商家已修改成功");
					} else {
						alert("所属商家修改失败，请刷新页面重试");
					}
				}
			});
		});

		// 修改
		$('#revise').click(function() {
			// 上传文件
			var logoFile = $("#logoFile")[0].files[0];
		    var picFile = $("#picFile")[0].files[0];
		    if(logoFile != null || logoFile != undefined){
		    	var fileName = logoFile.name.substring(logoFile.name.lastIndexOf(".")+1).toLowerCase();
				if(fileName !="jpg" && fileName !="jpeg" && fileName !="png"&& fileName !="gif" ){
					alert("只能上传.jpg  .png  .jpeg  .gif类型的文件!");
		            return false;
				}
		    	$("#logo").val(addfile(logoFile));
			}
		    if(picFile != null || picFile != undefined){
		    	var fileName = picFile.name.substring(picFile.name.lastIndexOf(".")+1).toLowerCase();
				if(fileName !="jpg" && fileName !="jpeg" && fileName !="png"&& fileName !="gif" ){
					alert("只能上传.jpg  .png  .jpeg  .gif类型的文件!");
		            return false;
				}
		    	$("#pic").val(addfile(picFile));
			}
		    var sotrename = $("#sotrename").val();
            if (sotrename.length == 0) {
            	alert('店铺名称不能为空');
                return false;
            }
            var address = $("#address").val();
            if (address.length == 0) {
            	alert('店铺地址不能为空');
                return false;
            }
            var latitude = $("#latitude").val();
            var longitude = $("#longitude").val();
            if (latitude.length == 0 || longitude.length == 0) {
            	alert('请输入正确的店铺地址信息，并检查地图的标注是否正确');
                return false;
            }
            $.ajax({
	            type: 'POST',
	            url : 'toUpdateSotre',
	            data : $('#myForm').serialize(),
	            dataType: 'json',
	            success : function(date) {
	            	switch (date) {
					case -1:
						alert("登录超时，请重新登录");
						top.location.href = "login/${titleId}";
						break;
					case 1:
						alert("修改成功");
						location.href = "sotreIndex?currentPageNo=${currentPageNo}&submobile=${submobile}&sotrename="
							+"${sotrename}&appname=${appname}&username=${username}&shopname=${shopname}&grade=${grade}&status=${status}";
						break;
					default:
						alert("修改失败，请重新操作");
						break;
					}
				}
	        });
		});
		
		function addfile(file) {
			var fm = new FormData();
			fm.append('file', file);
			$.ajax({
				url: '<%=basePath%>layfile/uploadFile1',
				type : 'POST',
				data : fm,
				async : false,
				contentType : false, //禁止设置请求类型
				processData : false, //禁止jquery对DAta数据的处理,默认会处理
				//禁止的原因是,FormData已经帮我们做了处理
				success : function(result) {
					file = result.json;
				}
			});
			return file;
		}
	</script>

	<script type="text/javascript">
		// 百度地图API功能
		var map = new BMap.Map("container");
		map.centerAndZoom(new BMap.Point('${sotre.latitude}', '${sotre.longitude}'), 16);
		map.addOverlay(new BMap.Marker(new BMap.Point('${sotre.latitude}', '${sotre.longitude}')));
		map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用
		map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
		map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
		
		var localSearch = new BMap.LocalSearch(map);
		$('#address').blur(function(event) {
			var keyword = $('#address').val();
			if (keyword.length == 0) {
				alert("请输入店铺地址信息");
				return false;
			}
			map.clearOverlays();//清空原来的标注
			localSearch.setSearchCompleteCallback(function(searchResult) {
				var poi = searchResult.getPoi(0);
				if (poi == null) {
					alert("请输入正确的店铺地址信息，并检查地图的标注是否正确");
					$("#latitude").val("");
					$("#longitude").val("");
					return false;
				}
				$("#latitude").val(poi.point.lng);
				$("#longitude").val(poi.point.lat);
				map.centerAndZoom(poi.point, 16);
				map.addOverlay(new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat))); // 创建标注
			});
			localSearch.search(keyword);			
		});
	</script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- validator -->
	<script src="<%=basePath%>vendors/validator/validator.js"></script>
</body>
</html>